//
//  GoodsDetailCtr-推荐.swift
//  smosky
//
//  Created by zhu xietong on 2018/5/22.
//  Copyright © 2018年 tianrun. All rights reserved.
//

import Foundation
import Eelay
import AsyncDisplayKit
import soapp

extension GoodsDetailCtr{
    class RecKit: JoTouchNode {
        let imgV = JoImageNode()
        let titleL = JoTextNode()
        let priceL = JoTextNode()
        
        
        
        override func specGetter() -> _Spec {
            let w = (Swidth - 2.0 * AppTheme.edge - 10)/3.0
            return _Spec.stack(["v|5","\(w + 50)",w,_nowrap], childs: [
                imgV[w,"\(w)"],
                titleL[_shrink(1)],
                priceL[_shrink(1)]
                ])
        }
        
        override func mo_model_reload() {
            imgV.img_url = mo.model["thumb",""]
            imgV.backgroundColor = ._cellBackground
            titleL.attributedText = mo.model.possible("title","subtitle", default: "").ui.font10.cl_666.lineSpace(6).astring
            priceL.attributedText = "\("¥".loc) \(mo.model[float:"marketprice",0].price_display)".ui.font10.color(color: ___shop.second).astring
            titleL.textNode.maximumNumberOfLines = 1
            priceL.textNode.maximumNumberOfLines = 1
            view.backgroundColor = .clear
        }
    }
    
    class WhiteCell: JoCellNode {
        let whiteV = ASDisplayNode()
        override func mo_model_reload() {
            view.backgroundColor = .clear
        }
        override func specGetter() -> _Spec {
            return _Spec.inset([], .zero, child: whiteV["20",Swidth])
        }
    }
    
    class RecItemCell: JoCellNode,EeActionDelegate{
        let listV = JoRuleNode<RecKit>()
        let leftV = ASDisplayNode()
        let rightV = ASDisplayNode()
        let tagV = ASTextNode2()
        
        func active(onwer: Any, actionID: String, data: NSMutableDictionary) {
            Goods.seeDetail(obj: data, at: content_controller)
        }
        
        override func specGetter() -> _Spec {
            
            let w = (Swidth - 24 - 60 - 2*AppTheme.edge)/2.0
            let spec:_Spec = _Spec.stack(["h|8","20",[10,0,15,0],_justfy(.space_between),&-.center,(Swidth-2*AppTheme.edge)], childs: [
                leftV["\(1)",_grow(1),w],
                tagV.Spec,
                rightV["\(1)",_grow(1),w]
                ])
            return _Spec.stack([[10,AppTheme.edge,26,AppTheme.edge],_grow(1)], childs: [
                spec,
                listV.Spec
                ])
        }
        
        
        override func mo_model_reload() {
            listV.space = 5
            listV.delegate = self
            listV.mo.model = mo.model
            view.backgroundColor = UIColor.clear
            leftV.backgroundColor = UIColor._separator
            rightV.backgroundColor = UIColor._separator
            tagV.attributedText = "为您推荐".loc.ui.font11.color(color: ._foregroundWeak).astring
            
            
        }
    }
}

